package com.hzhanghuan.materialsearchview.utils;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.os.Build;
import android.view.View;
import android.view.ViewAnimationUtils;


/**
 * Created by Administrator on 2016/7/7.
 */
public class AnimationUtils {

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void createCircularReveal(View view, int duration) {
        int x = view.getWidth();
        int y = view.getHeight()/2;
        float endRadius = (float) Math.hypot(x, y);
        Animator animator = ViewAnimationUtils.createCircularReveal(view, x, y, 0, endRadius);
        animator.setDuration(duration);
        animator.start();
    }





    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static void createCircularHide(View view, int duration, final OnHideAnimListener onHideAnimListener) {
        int x = view.getWidth();
        int y = view.getHeight()/2;
        float startRadius = (float) Math.hypot(x, y);
        Animator animator = ViewAnimationUtils.createCircularReveal(view, x, y, startRadius, 0);
        animator.setDuration(duration);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if(onHideAnimListener!=null){
                    onHideAnimListener.onAnimationEnd();
                }
            }
        });
        animator.start();
    }





    public interface OnHideAnimListener {
        void onAnimationEnd();
    }


}
